package com.kay.car.service;

import com.kay.car.dao.DogDao;
import com.kay.car.entity.DogTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DogService {
    @Autowired
    private DogDao dogDao;

    public List<String> findAll() {
        List<DogTable> dogs = dogDao.findAll();
        ArrayList<String> dogNames = new ArrayList<>();
        for (DogTable dogTable:dogs) {
            dogNames.add(dogTable.getName());
        }
        return dogNames;
    }

    public String addDog(String name) {
        DogTable dogTable = new DogTable();
        dogTable.setName(name);
        dogDao.save(dogTable);
        return "ok";
    }
}
